package lime49.lockcrypt.mobile;
import java.util.*;
import j2me.util.LinkedHashMap;

public class Account {
    public String name, type, icon, group;
    private Date created, modified;
    public AccType info;
    
    public Account(String name, String type, AccType info) {
        this.name = name;
        this.type = type;
        this.info = info;
    }
    public Account() {
        // used to construct a dummy account to show on the add form when adding a new account
        this.name = "";
        this.type = "Blank";
        this.icon = "default";
        this.group = "lockcrypt";
    }
    
    public Account(String name, String type, String icon, AccType info, String group, long created, long modified) {
        this.name = name;
        this.type = type;
        this.info = info;
        this.icon = icon;
        this.group = group;
        this.created = new Date(created);
        this.modified = new Date(modified);
    }
    
        /**
     * Returns whether or not to show the notes field for this account
     * @return True if the notes field should be shown, otherwise false
     */
    public boolean getShowNotes() {
        return info.getShowNotes();
    }
    
    /**
     * Returns the notes for this account
     * @return The notes for this account
     */
    public String getNotes() {
        return info.getNotes();
    }
    
    public String getName() {
        return name;
    }
    public long getCreated() {
        return created.getTime();
    }
    public long getModified() {
        return modified.getTime();
    }
    public Date getDateCreated() {
        return created;
    }
    public Date getDateModified() {
        return modified;
    }
    public String getIcon() {
        return icon;
    }
    
    public String getType() {
        return type;
    }
    
    public String getGroup() {
        return group;
    }
    public LinkedHashMap getInfo() {
        return info.getFieldMap();
    }
    public String getField(String name) {
        return info.getField(name);
    }
    public String getSearchString() {
        return name+type+info.getSearchString();
    }
    public String toString() {
        return name;
//        return "Name: "+name+"\nType: "+type+"\nIcon:"+icon+"\nInfo: "+info.fieldMapToString();
    }
    
    public int compareTo(Object otherObj) {
        Account otherAccount = (Account)otherObj;
        return name.toLowerCase().compareTo(otherAccount.getName().toLowerCase());
    }
}
